<template>
<!--添加工作经历-->
  <div class="ziliao">
      <div class="titleWrap">
        <p class="titleName">添加工作经历</p>
      </div>
      <div class="formWrapper">
        <Form :label-width="102" label-position="left" class="formMin"  ref="formValidate" :model="workcourse" :rules="ruleValidate" >
          <FormItem label="公司名称" prop="companyName">
            <Input  placeholder="请输入公司名称" v-model="workcourse.companyName" :maxlength="45"/>
          </FormItem>
          <FormItem label="职位名称" prop="position">
            <Select  v-model="workcourse.position" placeholder="请选择职位" >
              <Option :value="post.code" v-for="post in posts" :key="post.code">{{post.name}}</Option>
            </Select>
          </FormItem>
          <FormItem label="业态" prop="operationType">
            <Select  v-model="workcourse.operationType" placeholder="请选择业态">
              <Option :value="com.code" v-for="com in commercials" :key="com.code">{{com.name}}</Option>
            </Select>
          </FormItem>
          <FormItem label="工作年限" prop="workingLife">
            <Select  v-model="workcourse.workingLife" placeholder="请选择工作年限">
              <Option :value="year.name" v-for="year in workingYears" :key="year.name">{{year.text}}</Option>
            </Select>
          </FormItem>
          <FormItem label="工作描述" style="height:136px;width:700px;margin-bottom: 10px;" prop="workTask">
            <i-input type="textarea" :autosize="{minRows: 6,maxRows: 5}" placeholder="赶快添加工作描述吧~" :maxlength="450" v-model="workcourse.workTask"></i-input>
          </FormItem>
          <FormItem label="" style="width:700px;">
            <p class="tipwords">注：请填写真实工作经历，我们平台会对你提交的资料做背景调查，如虚假将加入企业黑名单。</p>
          </FormItem>
        </Form>
        <div class="keepThis"><span class="keepBtn" @click="save('formValidate')">保存</span></div>
      </div>
    <Spin fix v-show="isSpinShow" >
      <div class="loader">
        <Icon type="ios-loading" size=26 class="demo-spin-icon-load"></Icon>
        <div class="font14">加载中...</div>
      </div>
    </Spin>
  </div>
</template>
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped lang="less" rel="stylesheet/less">
  /* 旋转效果 */
  .demo-spin-icon-load{
    animation: ani-demo-spin 1s linear infinite;
  }
  @keyframes ani-demo-spin {
    from { transform: rotate(0deg);}
    50% { transform: rotate(180deg);}
    to { transform: rotate(360deg);}
  }
  /* 假如内容过长，一屏放不下，滚动条下拉覆盖不全 */
  .ivu-spin-fix {
    position: fixed;
  }

  .formWrapper{
    width: 330px;
    .tipwords{
      font-size: 14px;
      color: #666;
    }
  }
  .keepBtn {
    display: inline-block;
    width: 140px;
    height: 52px;
    background-color: #957960;
    text-align: center;
    line-height: 50px;
    color: #fff;
    font-size: 18px;
  }
  .keepBtn:hover {
    cursor: pointer;
  }
  .titleWrap {
    height: 40px;
    font-size: 20px;
    padding-bottom: 20px;
    color: #333;
    text-align: justify-all;
    border-bottom: 1px solid #E1E1E1;
    margin-bottom: 30px;
    .titleName {
      float: left;
      line-height: 24px;
    }
  }
  .keepThis {
    padding: 10px 0 0 102px;
  }
  .layoutSide {
    position: relative;
  }
</style>
<script type="text/ecmascript-6">
  import {workCourseAdd,workCourseSubmit,centreInfoWeb} from '../../http'
  import {getStore} from '../../storage'
    export default {
        name: '',
        props: {},
        data() {
            return {
              isSpinShow:false,
              commercials:'',      //业态
              posts:'',            //职位
              workingYears:'',     //工作年限
              workcourse:{         //工作经历
                companyName:'',     //公司名称
                operationType:'',   //业态
                position:'',        //职位
                workingLife:'',     //工作年限
                workTask:'',        //工作描述
              },
              //表单验证规则
              ruleValidate: {
                companyName: [
                  { required: true, message: '请填写公司名称', trigger: 'blur' }
                ],
                position: [
                  { required: true, message: '请选择职位', trigger: 'change' }
                ],
                operationType: [
                  { required: true, message: '请选择业态', trigger: 'change' },
                ],
                workingLife: [
                  { required: true, message: '请选择工作年限', trigger: 'change' }
                ],
                workTask: [
                  { required: true, message: '请填写工作描述',trigger: 'blur' },
                ],
              }
            };
        },
        methods: {
          save (name) {
            if(this.isSpinShow === false) {
              this.isSpinShow = true;
              //表单验证
              this.$refs[name].validate((valid) => {
                if (valid) {
                  //用户是否登录
                  centreInfoWeb().then(res => {
                    if (res.code === 200) {
                      //添加工作经历
                      workCourseSubmit({
                        companyName: this.workcourse.companyName,
                        operationType: this.workcourse.operationType,
                        position: this.workcourse.position,
                        workingLife: this.workcourse.workingLife,
                        workTask: this.workcourse.workTask
                      }).then(res => {
                        if (res.code === 200) {
                          this.isSpinShow = false;
                          this.$Notice.success({
                            title: '工作经历提醒',
                            desc: '工作经历添加成功! ',
                            duration: 3,
                          });
                          //添加成功后刷新表单内容
                          this.$refs[name].resetFields();
                          this.$router.push({
                            name: 'ziliao'
                          })
                        } else {
                          this.isSpinShow = false;
                          this.$Notice.warning({
                            title: '工作经历提醒',
                            desc: res.info,
                            duration: 3,
                          });
                        }
                      }).catch()
                    } else {
                      this.isSpinShow = false;
                      this.$parent.$refs.loginInput.showModal()
                    }
                  }).catch()
                }else {
                  this.isSpinShow = false;
                }
              }).catch()
            }
          },
          getAddJob(){
            if(this.isSpinShow === false) {
              this.isSpinShow = true;
              //用户是否登录
              centreInfoWeb().then(res => {
                if (res.code === 200) {
                  //获取工作经历页面信息
                  workCourseAdd().then(res => {
                    this.isSpinShow = false;
                    this.commercials = res.data.commercials;
                    this.posts = res.data.posts;
                    this.workingYears = res.data.workingYears;
                  }).catch()
                }else {
                  this.isSpinShow = false;
                }
              }).catch()
            }
          }
        },
        created() {
          this.getAddJob()
        },
        components: {
        }
    }
</script>
